import * as types from '../actions/actionTypes';

const initialState = {
    'ticketList' : [],
};

let viewTicketListReducer = (state = initialState, action) => {

     switch(action.type)
     {
        case types.FETCH_TICKET_LIST :
            return {
                 ...state,
            }
        case types.RECEIVE_TICKET_LIST :

            //这里需要将二位数组，处理成一维数组，存景区对象的。
            let tlist = action.ticketList;
            let arr = [];
            let res = {};
            for(let i = 0, j = tlist.length; i < j; i++){
                let ticket_arr_tmp = tlist[i];
                let view = {
                    'place_name' : '',
                    'place_code' : '',
                    'star' : 0,
                    'img' : '',
                    'address' : '',
                    'ticketarr' : [],
                };

                for(let m = 0, n = ticket_arr_tmp.length; m < n; m++){
                    let ticket_tmp = ticket_arr_tmp[m];

                    if(m === 0){
                        view['place_name'] = ticket_tmp.place_name;
                        view['place_code'] = ticket_tmp.place_code;
                        view['star'] = ticket_tmp.star;
                        view['img'] = ticket_tmp.img;
                        view['address'] = ticket_tmp.address;
                    }

                    let ticket = {
                        'sale_name' : ticket_tmp.sale_name,
                        'sale_code' : ticket_tmp.sale_code,
                        'sale_id' : ticket_tmp.sale_id,
                        'guide_price' : ticket_tmp.guide_price,
                    };

                    view['ticketarr'].push(ticket);

                }

                arr.push(view);
                //res[view['place_code']] = view;
            }

            return Object.assign({}, state, {
                'ticketList' : arr,
            })
        default : 
            return state;
     }
}

export default viewTicketListReducer;